<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace longbingcore\wxcore;

class Fdd
{
    protected static $uniacid;
    public function __construct($uniacid)
    {
        self::$uniacid = $uniacid;
        require_once EXTEND_PATH . "fdd/Fdd.Api.php";
        $this->getConfig();
    }
    public function getConfig()
    {
        $config_model = new \app\fdd\model\FddConfig();
        $config = $config_model->dataInfo(["uniacid" => self::$uniacid]);
        defined("FDD_ADDPID") || define("FDD_ADDPID", $config["AppId"]);
        defined("FDD_SECERT") || define("FDD_SECERT", $config["AppSecret"]);
        return $config;
    }
    public function registerAccount($user_id, $type = 1)
    {
        if($type == 1) {
            $user_model = new \app\massage\model\User();
            $open_id = $user_model->where(["id" => $user_id])->value("openid");
            if(empty($open_id)) {
                return ["code" => 500, "0" => "用户信息错误"];
            }
        } else {
            $open_id = "adminadminadmin" . $user_id;
        }
        $open_id = $open_id . $type;
        $open_id = str_replace("-", "", $open_id);
        $input = new \FddAccount();
        $input->SetOpenID($open_id);
        $input->SetAccountType($type);
        $res = \FddApi::registerAccount($input, 1);
        return $res;
    }
    public function getPersonVerifyUrl($customer_id)
    {
        $input = new \FddCertification();
        $input->SetCustomerID($customer_id);
        $input->SetVerifiedWay(9);
        $input->SetPageModify(1);
        $NotifyUrl = "https://" . $_SERVER["HTTP_HOST"] . "/massage/CallBack/fddAttestationCallBack";
        $input->SetNotifyUrl($NotifyUrl);
        $url = "https://" . $_SERVER["HTTP_HOST"] . "/h5/?#/pages/mine?type=2";
        $input->SetReturnUrl($url);
        $res = \FddApi::getPersonVerifyUrl($input);
        return $res;
    }
    public function getCompanyVerifyUrl($customer_id)
    {
        $input = new \FddCertification();
        $input->SetCustomerId($customer_id);
        $input->SetVerifiedWay(3);
        $input->SetMVerifieday(1);
        $input->SetPageModify(1);
        $NotifyUrl = "https://" . $_SERVER["HTTP_HOST"] . "/massage/CallBack/fddAttestationCallBack";
        $input->SetNotifyUrl($NotifyUrl);
        $res = \FddApi::getCompanyVerifyUrl($input);
        return $res;
    }
    public function FindPersonCertInfo($transactionNo)
    {
        $input = new \FddCertification();
        $input->SetVerifiedVSerialNo($transactionNo);
        $res = \FddApi::FindPersonCertInfo($input);
        return $res;
    }
    public function FindCompanyCertInfo($transactionNo)
    {
        $input = new \FddCertification();
        $input->SetVerifiedVSerialNo($transactionNo);
        $res = \FddApi::FindCompanyCertInfo($input);
        return $res;
    }
    public function getFile($uuid, $type = 1)
    {
        $input = new \FddCertification();
        $input->SetUUID($uuid);
        $input->SetDoc_type($type);
        $res = \FddApi::getFile($input);
        return $res;
    }
    public function ApplyCert($customer_id, $verified_serialno)
    {
        $input = new \FddCertification();
        $input->SetCustomerId($customer_id);
        $input->SetVerifiedVSerialNo($verified_serialno);
        $res = \FddApi::ApplyCert($input);
        return $res;
    }
    public function UploadSignatureContent($customer_id, $title)
    {
        $input = new \FddSignatureContent();
        $input->SetCustomerId($customer_id);
        $input->SetContent($title);
        $res = \FddApi::UploadSignatureContent($input);
        return $res;
    }
    public function GenerateContract($tmpl_id, $title, $map)
    {
        $input = new \FddTemplate();
        $input->SetDoc_title($title);
        $input->SetTemplate_id($tmpl_id);
        $input->SetContract_id(orderCode());
        $input->SetParameter_map($map);
        $res = \FddApi::GenerateContract($input);
        return $res;
    }
    public function UploadTemplateDocs($tmpl_id, $title, $doc_url)
    {
        $input = new \FddTemplate();
        $input->SetTemplate_name($title);
        $input->SetTemplate_id($tmpl_id);
        $input->SetDoc_url($doc_url);
        $res = \FddApi::uploadtemplate($input);
        return $res;
    }
    public function UploadTemplateDocsData($tmpl_id, $title, $doc_url)
    {
        $input = new \FddTemplate();
        $input->SetTemplate_name($title);
        $input->SetContract_template_id($tmpl_id);
        $input->SetFile($doc_url);
        $res = \FddApi::UploadTemplateDocs($input);
        return $res;
    }
    public function Uploaddocs($contract_id, $doc_title, $doc_url)
    {
        $input = new \FddTemplate();
        $input->SetContract_id($contract_id);
        $input->SetDoc_title($doc_title);
        $input->SetDoc_url($doc_url);
        $doc = substr($doc_url, strripos($doc_url, ".") + 1);
        $doc = "." . $doc;
        $input->SetDoc_type($doc);
        $res = \FddApi::Uploaddocs($input);
        return $res;
    }
    public function ExtsignAuto($transaction_id, $contract_id, $customer_id, $doc_title)
    {
        $input = new \FddSignContract();
        $input->SetTransaction_id($transaction_id);
        $input->SetContract_id($contract_id);
        $input->SetCustomer_id($customer_id);
        $input->SetDoc_title($doc_title);
        $input->SetClient_role(1);
        $input->SetPosition_type(0);
        $input->SetKeyword_strategy(2);
        $input->SetSign_keyword("甲方");
        $input->SetPagenum(0);
        $input->SetX(200);
        $input->SetY(800);
        $input->SetKeyx(100);
        $input->SetKeyy(0);
        $url = "https://" . $_SERVER["HTTP_HOST"] . "/#/sys/fdd-record";
        $input->SetReturn_url(urlencode($url));
        $res = \FddApi::ExtsignAuto($input);
        return $res;
    }
    public function Extsign($transaction_id, $contract_id, $customer_id, $doc_title, $type = 1)
    {
        $input = new \FddSignContract();
        $input->SetTransaction_id($transaction_id);
        $input->SetContract_id($contract_id);
        $input->SetCustomer_id($customer_id);
        $input->SetDoc_title($doc_title);
        $NotifyUrl = "https://" . $_SERVER["HTTP_HOST"] . "/massage/CallBack/fddSignCallBack";
        $input->SetNotify_url(urlencode($NotifyUrl));
        if($type == 1) {
            $url = "https://" . $_SERVER["HTTP_HOST"] . "/h5/?#/pages/mine?type=2";
            $input->SetReturn_url(urlencode($url));
        }
        $res = \FddApi::Extsign($input);
        return $res;
    }
    public function ContractFiling($contract_id)
    {
        $input = new \FddContractManageMent();
        $input->SetContract_id($contract_id);
        $res = \FddApi::ContractFiling($input);
        return $res;
    }
    public function DownLoadContract($contract_id)
    {
        $input = new \FddContractManageMent();
        $input->SetContract_id($contract_id);
        $res = \FddApi::DownLoadContract($input);
        return $res;
    }
    public function ViewContract($contract_id)
    {
        $input = new \FddContractManageMent();
        $input->SetContract_id($contract_id);
        $res = \FddApi::ViewContract($input);
        return $res;
    }
    public function getAutoAuth($company_customer_id)
    {
        $input = new \FddAuthSign();
        $input->SetTransaction_id(orderCode());
        $input->SetAuth_type(1);
        $input->SetContract_id(orderCode());
        $input->SetCustomerId($company_customer_id);
        $input->SetNotify_url("https://" . $_SERVER["HTTP_HOST"] . "/massage/CallBack/fddSignCallBacks");
        $url = "https://" . $_SERVER["HTTP_HOST"] . "/#/sys/fdd-record";
        $input->SetReturn_url(urlencode($url));
        $res = \FddApi::BeforeAuthsign($input);
        return $res;
    }
    public function findAutoAuth($company_customer_id)
    {
        $input = new \FddAuthSign();
        $input->SetCustomerId($company_customer_id);
        $res = \FddApi::GetAuthStatus($input);
        return $res;
    }
    public function CancelExtsignAutoPage($customer_id)
    {
        $input = new \FddAuthSign();
        $input->SetCustomerId($customer_id);
        $url = "https://" . $_SERVER["HTTP_HOST"] . "/#/sys/fdd-record";
        $input->SetReturn_url(urlencode($url));
        $input->SetNotify_url("https://" . $_SERVER["HTTP_HOST"] . "/massage/CallBack/fddSignCallBacks");
        $res = \FddApi::CancelExtsignAutoPage($input);
        return $res;
    }
}

?>